﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using ModuleDALCore;
using System.Data;

namespace DAL
{
    public class NHACUNGCAPDAO:DALBase
    {
        public NHACUNGCAPDAO()
        {
            this.OpenConnect();
        }
        private DataTable dt;
        private string _SpName;

        public string SpName
        {
            get { return "SPNHACUNGCAP"; }
            set { _SpName = value; }
        }
        public DataTable GetListNCC()
        {
            dt = new DataTable();
            try
            {

                dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new NHACUNGCAP(), null), ConvertClassToArray.GetValues(new NHACUNGCAP(), 0));
                return dt;
            }
			catch { return null; }//throw new InvalidExpressionException("Msg1: Can't list NCC"); }
        }
        public List<NHACUNGCAP> GetListNCCs()
        {
            dt = new DataTable();
            List<NHACUNGCAP> ds = new List<NHACUNGCAP>();
            try
            {

                dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new NHACUNGCAP(), null), ConvertClassToArray.GetValues(new NHACUNGCAP(), 0));
                ds = (List<NHACUNGCAP>)ConvertDatatableToList.ConvertTo<NHACUNGCAP>(dt);
               
            }
			catch { return null; }//throw new InvalidExpressionException("Msg1: Can't list NCC"); }
            return ds;
        }
		public List<NHACUNGCAP> ListNCCLABO()
		{
			dt = new DataTable();
			List<NHACUNGCAP> ds = new List<NHACUNGCAP>();
			try
			{

				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new NHACUNGCAP(), null), ConvertClassToArray.GetValues(new NHACUNGCAP(), 6));
				ds = (List<NHACUNGCAP>)ConvertDatatableToList.ConvertTo<NHACUNGCAP>(dt);

			}
			catch { return null; }//throw new InvalidExpressionException("Msg1: Can't list NCC"); }
			return ds;
		}
        public String CreatenewId()
        {
            try
            {
                return "NCC" + DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(new NHACUNGCAP(), null), ConvertClassToArray.GetValues(new NHACUNGCAP(), 1));

            }
			catch { return null; }//throw new InvalidExpressionException("Msg1: Can't Create new NCC"); }
        }
        public bool INSERT(NHACUNGCAP cv)
        {

            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 2)) == 1);

            }
			catch { return false; }//throw new InvalidExpressionException("Msg1: Can't Insert new NCC"); }
        }
        public bool UPDATE(NHACUNGCAP cv)
        {

            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 3)) == 1);

            }
			catch { return false; }//throw new InvalidExpressionException("Msg1: Can't Update  NCC"); }
        }
        public bool DELETE(NHACUNGCAP cv)
        {

            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 4)) == 1);

            }
			catch { return false; }//throw new InvalidExpressionException("Msg1: Can't Delete  NCC"); }
        }
        public List<NHACUNGCAP> Find(NHACUNGCAP ncc)
        {
              dt = new DataTable();
             List<NHACUNGCAP> ds = new List<NHACUNGCAP>();
             try
             {
                 dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(ncc, null), ConvertClassToArray.GetValues(ncc, 5));
                 ds = (List<NHACUNGCAP>)ConvertDatatableToList.ConvertTo<NHACUNGCAP>(dt);
             }
			 catch { return null; }//throw new InvalidExpressionException("Msg1: Can't Find  NCC"); }
             return ds;
        }
		public List<NHACUNGCAP> GetListNCCslabo()
		{
			dt = new DataTable();
			List<NHACUNGCAP> ds = new List<NHACUNGCAP>();
			try
			{
				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new NHACUNGCAP(), null), ConvertClassToArray.GetValues(new NHACUNGCAP(), 7));
				ds = (List<NHACUNGCAP>)ConvertDatatableToList.ConvertTo<NHACUNGCAP>(dt);
				return ds;
			}
			catch { return null; }//throw new InvalidExpressionException("Msg1: Can't list NCC"); }
		}
		public NHACUNGCAP GetNCCbyIDNCC(NHACUNGCAP ncc)
		{
			dt = new DataTable();
			NHACUNGCAP ds = new NHACUNGCAP();
			try
			{
				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(ncc, null), ConvertClassToArray.GetValues(ncc, 8));
				ds = (NHACUNGCAP)ConvertDatatableToList.ConvertToObject<NHACUNGCAP>(dt);
				return ds;
			}
			catch { return null; }//throw new InvalidExpressionException("Msg1: Can't list NCC"); }
		}
    }
}
